import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/layout/index.vue'; // 引入主布局组件
import NotFound from '@/views/404.vue'; // 引入404组件

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true // 通常登录页不在侧边栏显示
  },
  {
    path: '/404',
    component: NotFound,
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/intro', // 重定向到默认显示的子页面
    children: [
      {
        path: 'intro',
        name: 'Intro',
        component: () => import('@/views/intro/index.vue'),
        meta: { title: '首页', icon: 'HomeFilled', breadcrumb: false } // breadcrumb: false 表示不在面包屑中显示首页自身
      },
      {
        path: 'prepare', // 父级路由路径
        name: 'Prepare',
        // component: { render: () => h(RouterView) }, // 对于只有子路由的父级，可以这样或留空，Layout会处理
        redirect: '/prepare/upload-class', // 可选，如果直接访问 /prepare 则重定向
        meta: { title: '排课准备', icon: 'Tickets' }, // 父菜单的标题和图标
        children: [
          {
            path: 'semester',
            name: 'Semester',
            component: () => import('@/views/prepare/semester/index.vue'),
            meta: { title: '学期管理', icon: 'Calendar' }
          },
          {
            path: 'upload-class',
            name: 'UploadClass',
            component: () => import('@/views/prepare/uploadClass/index.vue'),
            meta: { title: '班级导入', icon: 'Upload' }
          },

          {
            path: 'upload-task',
            name: 'UploadTask',
            component: () => import('@/views/prepare/uploadTask/index.vue'),
            meta: { title: '任务导入', icon: 'Upload' }
          },
          // {
          //   path: 'task',
          //   name: 'Task',
          //   component: () => import('@/views/prepare/task/index.vue'),
          //   meta: { title: '任务管理', icon: 'List' }
          // },
          {
            path: 'upload-room',
            name: 'UploadRoom',
            component: () => import('@/views/prepare/uploadRoom/index.vue'),
            meta: { title: '教室导入', icon: 'Upload' }
          },

          {
            path: 'course',
            name: 'Course',
            component: () => import('@/views/prepare/course/index.vue'),
            meta: { title: '课程管理', icon: 'Avatar' }
          },
          {
            path: 'teacher',
            name: 'Teacher',
            component: () => import('@/views/prepare/teacher/index.vue'),
            meta: { title: '教师管理', icon: 'Avatar' }
          }
        ]
      },
      {
        path: '/scheduling',
        name: 'Scheduling',
        meta: {
          title: '排课', icon: 'el-icon-s-help'
        },
        children: [
          {
            path: 'auto',
            name: 'Auto',
            component: () => import('@/views/scheduling/auto/index.vue'),
            meta: { title: '排课任务' }
          },
          {
            path: 'handle',
            name: 'Handle',
            component: () => import('@/views/scheduling/handle/index.vue'),
            meta: { title: '手动解决冲突' }
          }
        ]
      },
      {
        path: '/table',
        name: 'Table',
        meta: {
          title: '排课结果', icon: 'el-icon-s-help'
        },
        children: [
          {
            path: 'classTable',
            name: 'ClassTable',
            component: () => import('@/views/table/classTable/index.vue'),
            meta: { title: '班级课表'}
          },
          {
            path: 'teacherTable',
            name: 'TeacherTable',
            component: () => import('@/views/table/teacherTable/index.vue'),
            meta: { title: '教师课表' }
          },
          {
            path: 'roomTable',
            name: 'RoomTable',
            component: () => import('@/views/table/roomTable/index.vue'),
            meta: { title: '教室课表' }
          }
        ]
      },
      {
        path : '/chat',
        name: 'Chat',
        component: () => import('@/views/chat/index.vue'),
        meta: {
          title: '聊天室', icon: 'el-icon-s-help'
        }
      }
      // {
      //   path: 'management',
      //   component: Layout, // 或者一个空的 <router-view> 组件作为父级
      //   redirect: '/management/users',
      //   name: 'Management',
      //   meta: { title: '系统管理', icon: 'Setting' },
      //   children: [
      //     {
      //       path: 'users',
      //       name: 'UserManagement',
      //       component: () => import('@/views/management/users.vue'),
      //       meta: { title: '用户管理' }
      //     },
      //     {
      //       path: 'roles',
      //       name: 'RoleManagement',
      //       component: () => import('@/views/management/roles.vue'),
      //       meta: { title: '角色管理' }
      //     }
      //   ]
      // }
    ]
  },
  // 捕获所有路由 - 必须放在最后
  // { path: '/:catchAll(.*)*', redirect: '/404', hidden: true }
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior: () => ({ top: 0 }),
  routes: constantRoutes
});

export default router;